std::numeric_limits
From Cppreference
| Defined in header
<limits> | ||
| template< class T > class numeric_limits;
| ||
The numeric_limits class template provides a standardized way to query about various properties of representation of fundamental types. This information is provided via specializations of the numeric_limits template. Specializations for fundamental types are already provided:
template<> class numeric_limits<bool>; template<> class numeric_limits<char>; template<> class numeric_limits<signed char>; template<> class numeric_limits<unsigned char>; template<> class numeric_limits<wchar_t>; template<> class numeric_limits<char16_t>; //C++0x feature template<> class numeric_limits<char32_t>; //C++0x feature template<> class numeric_limits<short>; template<> class numeric_limits<unsigned short>; template<> class numeric_limits<int>; template<> class numeric_limits<unsigned int>; template<> class numeric_limits<long>; template<> class numeric_limits<unsigned long>; template<> class numeric_limits<long long>; template<> class numeric_limits<unsigned long long>; template<> class numeric_limits<float>; template<> class numeric_limits<double>; template<> class numeric_limits<long double>;
Contents |
[edit] Members
^ Member ^ Default ^ Explanation ^ | static const bool is_specialized | false | true for all specializations of numeric_limits class template | | static const bool is_iec559 | false | true if the type adheres to IEC559 international standard (the same as IEEE 754). Meaningful for all floating point numbers. | | static const bool is_signed | false | true if the type is signed | | static const bool is_integer | false | true if the type is integer | | static const bool is_exact | false | true if the type uses an exact representation | | static const bool is_modulo | false | true if the type is modulo, i.e. if an operation consisting from *, + and - results in overflow then the final result differs from expected result by a multiple of integer (max() - min() + 1) | | static const bool is_bounded | false | true if the type uses has infinite set of representable values, i.e. arbitrary precision number |
[edit] Representable values
^ Member ^ Default ^ Explanation ^ | static T min() | {return T();} | minimum finite value. For floating point types: minimum denormalized value. Only meaningful if is_bounded is true | | static T max() | {return T();} | maximum finite value. Only meaningful if is_bounded is true | | static T lowest() | {return T();} | minimum finite value. Only meaningful if is_bounded is true (/C++0x feature)| | static const denorm_style has_denorm | denorm_absent | denorm_present if denormalized values are allowed, denorm_absent if not and denorm_indeterminate if this is not known at compile time. Meaningful for floating point types. | | static T denorm_min() | {return T();} | returns minimum positive denormalized value. If has_denorm is denorm_absent returns minimum positive normalized value. Meaningful for floating point types. | | static const bool has_infinity | false | true if the type can represent positive infinity. Shall be true for all specializations in which is_iec559 == true | | static T infinity() | {return T();} | returns positive infinity. Only meaningful if has_infinity is true. Required for all specializations in which is_iec559 == true |
[edit] Representation
^ Member ^ Default ^ Explanation ^ | static const int radix | 0 | base of the representation | | static const int min_exponent | 0 | minimum negative integer such that radix raised by power one less than that integer is a normalized floating point number. Meaningful for floating point types | | static const int min_exponent10 | 0 | minimum negative integer such that 10 raised by that power is a normalized floating point number. Meaningful for floating point types | | static const int max_exponent | 0 | maximum integer such that radix raised by power one less than that integer is a representable finite floating point number. Meaningful for floating point types | | static const int max_exponent10 | 0 | maximum integer such that 10 raised by that power is a representable finite floating point number. Meaningful for floating point types |
[edit] Precision
^ Member ^ Default ^ Explanation ^ | static const int digits | 0 | number of base radix digits that can be represented without losing precision| | static const int digits10 | 0 | number of decimal digits that can be represented without losing precision. Only meaningful if is_bounded is true | | static const int max_digits10 | 0 | number of decimal digits needed to represent any value without losing precision | | static const T epsilon() | {return T();} | the difference between 1.0 and the next representable value. Meaningful for all floating point types| | static const T round_error() | {return T();} | maximum possible rounding error | | static const bool has_denorm_loss | false | true if loss of precision is detected as a denormalization loss, rather than as an inexact result | | static const float_round_style round_style | round_towards_zero | floating point rounding mode. Meaningful for floating point types. Integer types shall return round_towards_zero|
[edit] Not-a-numbers (NaNs)
^ Member ^ Default ^ Explanation ^ | static const bool has_signaling_NaN | false | true if the type can represent signaling not-a-number (NaN). Shall be true if is_iec559 == true | | static const bool has_quiet_NaN | false | true if the type can represent non-signaling (quiet) not-a-number (NaN). Shall be true if is_iec559 == true | | static T signaling_NaN() | {return T();} | returns signaling not-a-number (NaN). Only meaningful if has_signaling_NaN is true. Required if is_iec559 == true | | static T quiet_NaN() | {return T();} | returns non-signalling (quiet) not-a-number (NaN). Only meaningful if has_quiet_NaN is true. Required if is_iec559 == true |
[edit] Miscellaneous
| static const bool traps | false | true if it is possible for trap to happen | | static const bool tinyness_before | false | true if tinyness is detected before rounding. Meaningful for floating point types. |
[edit] Relationship with macro constants of C library
| Specialization | Members | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| min() | max() | epsilon() | digits() | digits10() | min_exponent() | min_exponent10() | max_exponent() | max_exponent10() | |||
| numeric_limits< bool > | |||||||||||
| numeric_limits< char > | CHAR_MIN | CHAR_MAX | |||||||||
| numeric_limits< signed char > | SCHAR_MIN | SCHAR_MAX | |||||||||
| numeric_limits< unsigned char > | 0 | UCHAR_MAX | |||||||||
| numeric_limits< wchar_t > |
| ||||||||||
| numeric_limits< char16_t > |
| ||||||||||
| numeric_limits< char32_t > |
| ||||||||||
| numeric_limits< short > | SHRT_MIN | SHRT_MAX | |||||||||
| numeric_limits< signed short > | |||||||||||
| numeric_limits< unsigned short > | USHRT_MIN | USHRT_MAX | |||||||||
| numeric_limits< int > | INT_MIN | INT_MAX | |||||||||
| numeric_limits< signed int > | |||||||||||
| numeric_limits< unsigned int > | 0 | UINT_MAX | |||||||||
| numeric_limits< long > | LONG_MIN | LONG_MAX | |||||||||
| numeric_limits< signed long > | |||||||||||
| numeric_limits< unsigned long > | 0 | ULONG_MAX | |||||||||
| numeric_limits< long long > | LLONG_MIN | LLONG_MAX | |||||||||
| numeric_limits< signed long long > | |||||||||||
| numeric_limits< unsigned long long > | 0 | ULLONG_MAX | |||||||||
| numeric_limits< float > | FLT_MIN | FLT_MAX | FLT_EPSILON | FLT_MANT_DIG | FLT_DIG | FLT_MIN_EXP | FLT_MIN_10_EXP | FLT_MAX_EXP | FLT_MAX_10_EXP | ||
| numeric_limits< double > | DBL_MIN | DBL_MAX | DBL_EPSILON | DBL_MANT_DIG | DBL_DIG | DBL_MIN_EXP | DBL_MIN_10_EXP | DBL_MAX_EXP | DBL_MAX_10_EXP | ||
| numeric_limits< long double > | LDBL_MIN | LDBL_MAX | LDBL_EPSILON | LDBL_MANT_DIG | LDBL_DIG | LDBL_MIN_EXP | LDBL_MIN_10_EXP | LDBL_MAX_EXP | LDBL_MAX_10_EXP
}} |
||